﻿using System;
using System.Collections.Generic;
using System.Windows.Threading;
using Caliburn.Micro;
using JY.Wpf.Core.Tools;
using JY.Wpf.Core.ViewModelBases;
using JY.Wpf.Test.Views.MVVMDemoViews;
using SD.IOC.Core.Mediators;

namespace JY.Wpf.Test.ViewModels.MVVMDemoViewModels
{
    /// <summary>
    /// 储区测试ViewModel
    /// </summary>
    [NotifyPropertyChanged]
    public class StorageAreaTestViewModel:ViewModelBase
    {
        #region # 变量

        #endregion

        #region # 构造器
        /// <summary>
        /// 构造器
        /// </summary>
        public StorageAreaTestViewModel()
        {
            this.StorageAreas = new Dictionary<StorageArea, List<MaterialStock>>();
            List<MaterialStock> materialStocks = new List<MaterialStock>();
            materialStocks.Add(new MaterialStock() { Name = "测试1", Number = "001", Phy = 20 });
            materialStocks.Add(new MaterialStock() { Name = "测试2", Number = "002", Phy = 30 });
            materialStocks.Add(new MaterialStock() { Name = "测试3", Number = "003", Phy = 40 });
            materialStocks.Add(new MaterialStock() { Name = "测试4", Number = "004", Phy = 50 });
            materialStocks.Add(new MaterialStock() { Name = "测试5", Number = "005", Phy = 60 });

            this.StorageAreas.Add(new StorageArea("称量储区", "001", "备注"), materialStocks);
            this.StorageAreas.Add(new StorageArea("分拣储区", "002", "备注"), materialStocks);
            this.StorageAreas.Add(new StorageArea("脱包储区", "003", "备注"), materialStocks);
            this.StorageAreas.Add(new StorageArea("投料储区", "004", "备注"), materialStocks);
            this.StorageAreas.Add(new StorageArea("暂存储区", "005", "备注"), materialStocks);
            this.StorageAreas.Add(new StorageArea("称量储区1", "006", "备注"), materialStocks);
            this.StorageAreas.Add(new StorageArea("分拣储区2", "007", "备注"), materialStocks);
            this.StorageAreas.Add(new StorageArea("脱包储区3", "008", "备注"), materialStocks);
            this.StorageAreas.Add(new StorageArea("投料储区4", "009", "备注"), materialStocks);
            this.StorageAreas.Add(new StorageArea("暂存储区5", "010", "备注"), materialStocks);
            DispatcherTimer timer = new DispatcherTimer();
            timer.Interval = TimeSpan.FromSeconds(2);
            timer.Tick += (s, e) =>
            {
                Random random = new Random();
                foreach (var storageAreaItem in this.StorageAreas)
                {
                    storageAreaItem.Key.Status = random.Next(0, 3);
                }
            };
            timer.Start();
        }
        #endregion

        #region # 属性
        public Dictionary<StorageArea, List<MaterialStock>> StorageAreas { get; set; }
        #endregion

        #region # Command方法

        public void Flipper()
        {
            this.IsFlipped = !this.IsFlipped;
        }
        #endregion

        #region # 方法

        #endregion

        #region # 获取页面 —— object GetView(object context = null)
        /// <summary>
        /// 获取页面
        /// </summary>
        /// <param name="context">页面</param>
        /// <returns></returns>
        public override object GetView(object context = null)
        {
            return ResolveMediator.Resolve<StorageAreaTestView>();
        }
        #endregion
    }

    [NotifyPropertyChanged]
    public class MaterialStock
    {
        public string Name { get; set; }
        public string Number { get; set; }
        public double Phy { get; set; }
    }

    [NotifyPropertyChanged]
    public class StorageArea : PropertyChangedBase
    {
        public StorageArea(string name, string number, string remark)
        {
            Name = name;
            Number = number;
            Remark = remark;
        }

        public int Status { get; set; }

        public string Name { get; set; }
        public string Number { get; set; }
        public string Remark { get; set; }
    }
}
